{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "private_outputs": true,
      "provenance": [],
      "authorship_tag": "ABX9TyOTpXLwexsGPgxr+sBhR3g2",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/ktynski/Marketing_Automations_Notebooks_With_GPT/blob/main/Automatic_Persona_and_Motivation_Research_(public).ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!pip install openai"
      ],
      "metadata": {
        "id": "ONsc0cAyStkt"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Initialize the OpenAI API key\n",
        "import openai\n",
        "openai.api_key = \"your api key\"\n",
        "model_engine = \"text-davinci-003\""
      ],
      "metadata": {
        "id": "ldLCxJbESwqc"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "import concurrent.futures\n",
        "import pandas as pd\n",
        "import openai\n",
        "\n",
        "\n",
        "\n",
        "def generate_answer(prompt):\n",
        "    response = openai.Completion.create(\n",
        "        engine=model_engine,\n",
        "        prompt=prompt,\n",
        "        max_tokens=1024,\n",
        "        n=1,\n",
        "        stop=None,\n",
        "        temperature=0.5,\n",
        "    )\n",
        "    result = response[\"choices\"][0][\"text\"].strip()\n",
        "    return result\n",
        "\n",
        "def generate_questions(keyword):\n",
        "    questions = [\n",
        "            \"What is the average age range of individuals who are interested in \" + keyword + \"?\",\n",
        "            \"What is the typical income range of individuals who purchase \" + keyword + \"?\",\n",
        "            \"What level of education do individuals who are interested in \" + keyword + \" typically have?\",\n",
        "            \"What is the dominant geographic location of individuals who seek out \" + keyword + \"?\",\n",
        "            \"What are the most common job titles of individuals who are interested in \" + keyword + \"?\",\n",
        "            \"What industries do individuals who purchase \" + keyword + \" typically work in?\",\n",
        "            \"What is the gender breakdown of individuals who seek out \" + keyword + \"?\",\n",
        "            \"What are the top personality traits of individuals who are interested in \" + keyword + \"?\",\n",
        "            \"What values do individuals who purchase \" + keyword + \" typically hold?\",\n",
        "            \"What are the most common interests and hobbies of individuals who are interested in \" + keyword + \"?\",\n",
        "            \"What motivates individuals to seek out \" + keyword + \"?\",\n",
        "            \"What specific problems or challenges do individuals who are interested in \" + keyword + \" want to solve?\",\n",
        "            \"What are the specific outcomes or goals that individuals want to achieve through searching for \" + keyword + \"?\",\n",
        "            \"What benefits do individuals hope to receive from \" + keyword + \"?\",\n",
        "            \"What solutions are individuals currently using to address their problems related to \" + keyword + \"?\",\n",
        "            \"How effective are the current solutions that individuals use for \" + keyword + \"?\",\n",
        "            \"On a scale of 1 to 10, how satisfied are individuals with the current solutions they use for \" + keyword + \"?\",\n",
        "            \"What obstacles or challenges do individuals face when trying to find solutions for \" + keyword + \"?\",\n",
        "            \"What are the common pain points or difficulties that individuals experience when searching for \" + keyword + \"?\",\n",
        "            \"What points of frustration or dissatisfaction do individuals have with the current solutions for \" + keyword + \"?\",\n",
        "            \"What digital devices do individuals typically use when researching and purchasing \" + keyword + \"?\",\n",
        "            \"What websites, social media platforms, and online communities do individuals who are interested in \" + keyword + \" engage with?\",\n",
        "            \"How important is online research and customer reviews to individuals when making decisions about \" + keyword + \"?\",\n",
        "            \"What are the specific pain points or challenges that individuals experience when using \" + keyword + \"?\",\n",
        "            \"What fears or concerns do individuals have when making decisions related to \" + keyword + \"?\",\n",
        "            \"What unexpected challenges have individuals faced when using \" + keyword + \"?\",\n",
        "            \"What market trends are currently impacting the demand for \" + keyword + \"?\",\n",
        "            \"What opportunities exist for companies offering \" + keyword + \"?\"\n",
        "        ]\n",
        "    return questions\n",
        "\n",
        "def build_dataframe(keyword):\n",
        "    questions = generate_questions(keyword)\n",
        "    answers = []\n",
        "    with concurrent.futures.ThreadPoolExecutor() as executor:\n",
        "        answers = list(executor.map(generate_answer, questions))\n",
        "    data = {\n",
        "        \"Keyword\": [keyword],\n",
        "        \"What is the average age range of individuals who are interested in your keyword?\": [answers[0]],\n",
        "        \"What is the typical income range of individuals who purchase your keyword?\": [answers[1]],\n",
        "        \"What level of education do individuals who are interested in your keyword typically have?\": [answers[2]],\n",
        "        \"What is the dominant geographic location of individuals who seek out your keyword\": [answers[3]],\n",
        "        \"What are the most common job titles of individuals who are interested in your keyword?\": [answers[4]],\n",
        "        \"What industries do individuals who purchase your keyword typically work in?\": [answers[5]],\n",
        "        \"What is the gender breakdown of individuals who seek out your keyword?\": [answers[6]],\n",
        "        \"What are the top personality traits of individuals who are interested in your keyword?\": [answers[7]],\n",
        "        \"What values do individuals who purchase your keyword typically hold?\": [answers[8]],\n",
        "        \"What are the most common interests and hobbies of individuals who are interested in your keyword?\": [answers[9]],\n",
        "        \"What motivates individuals to seek out your keyword?\": [answers[10]],\n",
        "        \"What specific problems or challenges do individuals who are interested in your keyword want to solve?\": [answers[11]],\n",
        "        \"What are the specific outcomes or goals that individuals want to achieve through searching for your keyword?\": [answers[12]],\n",
        "        \"What benefits do individuals hope to receive from your keyword?\": [answers[13]],\n",
        "        \"What solutions are individuals currently using to address their problems related to your keyword?\": [answers[14]],\n",
        "        \"How effective are the current solutions that individuals use for your keyword?\": [answers[15]],\n",
        "        \"On a scale of 1 to 10, how satisfied are individuals with the current solutions they use for your keyword?\": [answers[16]],\n",
        "        \"What obstacles or challenges do individuals face when trying to find solutions for your keyword?\": [answers[17]],\n",
        "        \"What are the common pain points or difficulties that individuals experience when searching for your keyword?\": [answers[18]],\n",
        "        \"What points of frustration or dissatisfaction do individuals have with the current solutions for your keyword?\": [answers[19]],\n",
        "        \"What digital devices do individuals typically use when researching and purchasing your keyword?\": [answers[20]],\n",
        "        \"What websites, social media platforms, and online communities do individuals who are interested in your keyword engage with?\": [answers[21]],\n",
        "        \"How important is online research and customer reviews to individuals when making decisions about your keyword?\": [answers[22]],\n",
        "        \"What are the specific pain points or challenges that individuals experience when using your keyword\": [answers[23]],\n",
        "        \"What fears or concerns do individuals have when making decisions related to your keyword\": [answers[24]],\n",
        "        \"What unexpected challenges have individuals faced when using your keyword\": [answers[25]],\n",
        "        \"What market trends are currently impacting the demand for your keyword\": [answers[26]],\n",
        "        \"What opportunities exist for companies offering your keyword\": [answers[27]],\n",
        "\n",
        "    }\n",
        "    df = pd.DataFrame(data)\n",
        "    return df\n",
        "\n",
        "def generate_final_dataframe(keywords):\n",
        "    dfs = []\n",
        "    with concurrent.futures.ThreadPoolExecutor() as executor:\n",
        "        dfs = list(executor.map(build_dataframe, keywords))\n",
        "    final_df = pd.concat(dfs)\n",
        "    return final_df\n",
        "\n",
        "if __name__ == \"__main__\":\n",
        "    keywords = [\"PR Software\", \"Dog training services in Denver\", \"High quality t-shirts for men\"]\n",
        "    final_df = generate_final_dataframe(keywords)\n",
        "    print(final_df)\n",
        "    final_df.to_csv(\"Persona_Research_Results.csv\")\n"
      ],
      "metadata": {
        "id": "R69muBu_zKX2"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}